#include <stdio.h>
#include <string.h>
#include <stdbool.h>

const char* week[7] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};

bool isA_Z(char c){
	return (c >= 'A' && c <= 'Z');
}

bool isa_z(char c){
	return (c >= 'a' && c <= 'z');
}

bool is0_9(char c){
	return (c >= '0' && c <= '9');
}

int main()
{
	char data[4][100];
	int i = 0, sum = 0;
	int day = 0, hour = 0, min = 0;
	printf("请输入福尔摩斯码: \n");
	//输入4个密码	
	for(i = 0; i < 4; i++){
		scanf("%s", &data[i]);
	}
	//根据第一和第二个密码推出Day和hour
	while(data[0][i] != '\0' && data[1][i] != '\0'){
		if(data[0][i] == data[1][i] && (is0_9(data[0][i]) || isA_Z(data[0][i]))){
			//第一对 大写字母相等
			if(sum == 0 && isA_Z(data[0][i])){
				day  = data[0][i] - 'A';
				sum++;
				i++;
				continue;
			}
			//第二对 大写字母或者数字相等
			if(sum == 1){
				if(isA_Z(data[0][i])){
					hour = data[0][i] - 'A' + 10;
				}
				else{
					hour = data[0][i];
				}
				break;
			}
		}
		i++;
	}
	i = 0;
	//根据后2对密码，推出分钟
	while(data[2][i] != '\0' && data[3][i] != '\0'){
		if(data[2][i] == data[3][i] && isa_z(data[2][i])){
			min = i;
			break;
		}
		i++;
	}
	//输出制定格式
	printf("%s %2d:%02d\n", week[day], hour, min);
	
	return 0;
}

